package cn.shengchao.examstar.ai.domain.valueobject;

import lombok.Getter;

/**
 * 学习计划状态值对象
 * 定义学习计划的各种状态及其转换规则
 */
@Getter
public enum StudyPlanStatus {
    
    DRAFT("DRAFT", "草稿", "学习计划已创建但未开始"),
    ACTIVE("ACTIVE", "进行中", "学习计划正在进行中"),
    PAUSED("PAUSED", "暂停", "学习计划已暂停"),
    COMPLETED("COMPLETED", "已完成", "学习计划已完成"),
    CANCELLED("CANCELLED", "已取消", "学习计划已取消");
    
    private final String code;
    private final String name;
    private final String description;
    
    StudyPlanStatus(String code, String name, String description) {
        this.code = code;
        this.name = name;
        this.description = description;
    }
    
    /**
     * 根据代码获取状态
     */
    public static StudyPlanStatus fromCode(String code) {
        if (code == null) {
            throw new IllegalArgumentException("状态代码不能为空");
        }
        
        for (StudyPlanStatus status : values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        
        throw new IllegalArgumentException("无效的状态代码: " + code);
    }
    
    /**
     * 判断是否可以转换到目标状态
     */
    public boolean canTransitionTo(StudyPlanStatus targetStatus) {
        if (targetStatus == null) {
            return false;
        }
        
        switch (this) {
            case DRAFT:
                return targetStatus == ACTIVE || targetStatus == CANCELLED;
            case ACTIVE:
                return targetStatus == PAUSED || targetStatus == COMPLETED || targetStatus == CANCELLED;
            case PAUSED:
                return targetStatus == ACTIVE || targetStatus == CANCELLED;
            case COMPLETED:
            case CANCELLED:
                return false; // 终态，不能再转换
            default:
                return false;
        }
    }
    
    /**
     * 判断是否为进行中状态
     */
    public boolean isInProgress() {
        return this == ACTIVE;
    }
    
    /**
     * 判断是否为终态
     */
    public boolean isTerminal() {
        return this == COMPLETED || this == CANCELLED;
    }
    
    /**
     * 判断是否可以修改学习计划
     */
    public boolean canModify() {
        return this == DRAFT || this == ACTIVE || this == PAUSED;
    }
}